﻿using System;
using UnityEngine;

public class PlayerMana : MonoBehaviour
{
    [Header("配置")]
    [SerializeField] private PlayerStats stats;
    
    public float CurrentMana { get; set; }

    private void Start()
    {
        ResetMana();
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.O))
        {
            UseMana(3);
        }
    }

    public void UseMana(float amount)
    {
        stats.Mana = Mathf.Max(stats.Mana -= amount, 0f);
        CurrentMana = stats.Mana;
    }

    public void ResetMana()
    {
        CurrentMana = stats.MaxMana;
    }

    public bool CanRestoreMana()
    {
        return stats.Mana < stats.MaxMana && stats.Mana > 0;
    }
    
    public void RestoreMana(float amount)
    {
        stats.Mana = Mathf.Min(stats.Mana += amount, stats.MaxMana);
    }
}